package com.delianna.bwt;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;

import com.delianna.bwt.data.XmlParser;
import com.delianna.bwt.helpers.AppStatus;
import com.delianna.bwt.models.BWT;

/**
 * @author Delio Castillo (jangeador@gmail.com)
 *
 */
public class SplashScreenActivity extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// set the content view for your splash screen you defined in an xml
		// file
		setContentView(R.layout.splash);

		// perform other stuff you need to do
		new SimpleEula(this).show();

		// execute your xml loader
		new AsyncLoadXMLFeed().execute();

	}

	private class AsyncLoadXMLFeed extends AsyncTask<Void, Void, Void> {

		private BWT bwt;
			@Override
			protected void onPreExecute() {
				// show your progress dialog

			}

			@Override
			protected Void doInBackground(Void... params) {
				// load your xml feed asynchronously

				// parse me
				boolean isOnline = AppStatus.getInstance(SplashScreenActivity.this).isOnline(SplashScreenActivity.this);
				bwt = XmlParser.Parse(isOnline);

				return null;
			}

			@Override
			protected void onPostExecute(Void params) {
				// dismiss your dialog
				// launch your activity
				Intent intent = new Intent(SplashScreenActivity.this,
						PortListActivity.class);
				intent.putExtra("com.delianna.bwt.models.BWT", bwt);
				startActivity(intent);
		
				// close this activity
				finish();
			}

		}
}